using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using DbFramework.Data.ORM.Attributes;
namespace DbFramework.Data.ORM
{
    [Serializable]
    internal class FieldDescriptor : PropertyDescriptor
    {
        private Field _field;

        public FieldDescriptor(Field field)
            : base(field.PropertyName, null)
        {
            this._field = field;
        }
       
        public override bool CanResetValue(object component)
        {
            return false;
        }

        public override Type ComponentType
        {
            get
            {
                return null;
            }
        }

        public override object GetValue(object component)
        {
            BaseEntity obj = (BaseEntity)component;
           return obj.GetField(_field.PropertyName);        
        }

        public override void SetValue(object component, object value)
        {
            BaseEntity obj = (BaseEntity)component;
            obj.SetField(_field.PropertyName, value);            
        }

        public override bool IsReadOnly
        {
            get
            {
                return false;
            }
        }

        public override Type PropertyType
        {
            get
            {
                return _field.FieldType;
            }
        }

        public override void ResetValue(object component)
        {

        }

        public override bool ShouldSerializeValue(object component)
        {
            return true;
        }
    }
}
